#include "TextManager.h"


TextManager::TextManager() {
}


TextManager::~TextManager() {
}


void TextManager::Initialize(sf::RenderWindow* window) {
	m_font_Score = new sf::Font();
	m_font_Score->loadFromFile("font/BatmanForeverAlternate.ttf");

	// AmmoMeter stuff
	m_renderWindow = window;
	fade = 255;
	color = new sf::Color();
	color->a = fade;
	color->r = 255;
	color->g = 255;
	color->b = 255;
	clipAmmoText = new sf::Text();
	totalAmmoText = new sf::Text();
	slash = new sf::Text();
	ammoFont = new sf::Font();
	ammoFont->loadFromFile("font/comic.ttf");
	clipAmmoText->setFont(*ammoFont);
	clipAmmoText->setCharacterSize(25);
	clipAmmoText->setString("x");

	totalAmmoText->setFont(*ammoFont);
	totalAmmoText->setCharacterSize(25);
	totalAmmoText->setString("x");

	slash->setFont(*ammoFont);
	slash->setCharacterSize(40);
	slash->setString("/");

}

void TextManager::addMutantScore(sf::RenderWindow* m_renderWindow, EnemyManager* enyman) {
	//MutantScore mutantScoreObj;
	mutantScoreObj = new MutantScore;
	mutantScoreObj->Initialize(m_renderWindow,  enyman,m_font_Score);
	m_arrayOfMutantScore.push_back(mutantScoreObj);

}
void TextManager::addBossScore(sf::RenderWindow* m_renderWindow, EnemyManager* enyman) {
	//MutantScore mutantScoreObj;
	bossScoreObj = new BossScore;
	bossScoreObj->Initialize(m_renderWindow,  enyman,m_font_Score);
	m_arrayOfBossScore.push_back(bossScoreObj);

}
void TextManager::addRaiderScore(sf::RenderWindow* m_renderWindow, EnemyManager* enyman) {
	//MutantScore mutantScoreObj;
	raiderScoreObj = new RaiderScore;
	raiderScoreObj->Initialize(m_renderWindow,  enyman,m_font_Score);
	m_arrayOfRaiderScore.push_back(raiderScoreObj);

}

void TextManager::addTriplekill(sf::RenderWindow* m_renderWindow) {
	tripleKillObj = new tripleKill;
	tripleKillObj->Initialize(m_renderWindow, m_font_Score);
	m_arrayOfTriplekill.push_back(tripleKillObj);

}
void TextManager::addMultikill(sf::RenderWindow* m_renderWindow) {
	multiKillObj = new multiKill;
	multiKillObj->Initialize(m_renderWindow, m_font_Score);
	m_arrayOfMultikill.push_back(multiKillObj);

}

void TextManager::addMonsterkill(sf::RenderWindow* m_renderWindow) {
	monsterKillObj = new monsterKill;
	monsterKillObj->Initialize(m_renderWindow, m_font_Score);
	m_arrayOfMonsterkill.push_back(monsterKillObj);

}



void TextManager::Update() {
		for(int i = 0; i < m_arrayOfMutantScore.size(); i++) {
			m_arrayOfMutantScore[i]->Update();
		}
		for(int i = 0; i < m_arrayOfBossScore.size(); i++) {
			m_arrayOfBossScore[i]->Update();
		}
		for(int i = 0; i < m_arrayOfRaiderScore.size(); i++) {
			m_arrayOfRaiderScore[i]->Update();
		}
		for(int i = 0; i < m_arrayOfTriplekill.size(); i++) {
			m_arrayOfTriplekill[i]->Update();
		}
		for(int i = 0; i < m_arrayOfMultikill.size(); i++) {
			m_arrayOfMultikill[i]->Update();
		}
		for(int i = 0; i < m_arrayOfMonsterkill.size(); i++) {
			m_arrayOfMonsterkill[i]->Update();
		}
}

void TextManager::update_ammoText(Input* inputObj)
{
	clipAmmoText->setPosition(sf::Vector2f(m_renderWindow->convertCoords(sf::Vector2i(43.0, 637.0f))));
	slash->setPosition(sf::Vector2f(m_renderWindow->convertCoords(sf::Vector2i(67.0, 628.0f))));
	totalAmmoText->setPosition(sf::Vector2f(m_renderWindow->convertCoords(sf::Vector2i(87.0, 637.0f))));

	if(inputObj->m_player->equipPistol == true)
	{
		clipAmmoText->setString(convertInt(inputObj->gun_clip_ammo));
		totalAmmoText->setString(convertInt(inputObj->gun_total_ammo));
	}

	if(inputObj->m_player->equipMachinegun == true)
	{
		clipAmmoText->setString(convertInt(inputObj->machinegun_clip_ammo));
		totalAmmoText->setString(convertInt(inputObj->machinegun_total_ammo));
	}

	if(inputObj->m_player->equipShotgun == true)
	{
		clipAmmoText->setString(convertInt(inputObj->shotgun_clip_ammo));
		totalAmmoText->setString(convertInt(inputObj->shotgun_total_ammo));
	}

	m_renderWindow->draw(*clipAmmoText);
	m_renderWindow->draw(*slash);
	m_renderWindow->draw(*totalAmmoText);
}

std::string TextManager::convertInt(int number)
{
   std::stringstream ss;
   ss << number;
   return ss.str();
}

void TextManager::Cleanup() {
	delete m_font_Score;
	delete mutantScoreObj;
	delete raiderScoreObj;
	delete bossScoreObj;
	delete tripleKillObj;
	delete multiKillObj;
	delete monsterKillObj;
}
